home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / kiss-0.11 / kiss-0 / kiss / src / docat.c < prev    next >
C/C++ Source or Header  |  1995-03-23  |  934b  |  50 lines

  1. #include "kiss.h"
  2.  
  3. int docat (Stringstack s)
  4. {
  5.     register int
  6.     showall = 0,
  7.     printonly = 0,
  8.     i,
  9.     ret = 0,
  10.     opt;
  11.     FILE
  12.     *inf;
  13.  
  14.     while ( (opt = getopt (s.nstr, s.str, "hsp")) != -1 )
  15.     switch (opt)
  16.     {
  17.         case 'p':
  18.         printonly++;
  19.         break;
  20.         case 's':
  21.         showall++;
  22.         break;
  23.         case 'h':
  24.         default:
  25.         error ("Bad commandline.\n"
  26.                "Usage: %s [-hps] [file(s)]\n"
  27.                "Where:\n"
  28.                "    -h: this message\n"
  29.                "    -p: show only printable chars\n"
  30.                "    -s: show filenames while cat-ting\n"
  31.                "    file(s): files to copy to stdout\n",
  32.                progname);
  33.     }
  34.  
  35.     if (optind >= s.nstr)
  36.     catfile (stdin, "stdin", showall, printonly);
  37.     else for (i = optind; i < s.nstr; i++)
  38.     {
  39.     if (! (inf = fopen (s.str [i], "r")) )
  40.         ret += warning ("cannot open \"%s\"", s.str [i]);
  41.     else
  42.     {
  43.         catfile (inf, s.str [i], showall, printonly);
  44.         fclose (inf);
  45.     }
  46.     }
  47.  
  48.     return (ret);
  49. }
  50.